package com.dai.zhenfujin.my.activity.wallet;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dai.zhenfujin.Constants.Constants;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.base.BaseActivity;
import com.dai.zhenfujin.http.CallBack;
import com.dai.zhenfujin.http.HttpClient;
import com.dai.zhenfujin.my.bean.AccountBean;
import com.dai.zhenfujin.utils.UIUtils;

import java.util.HashMap;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class AccountDetailsActivity extends BaseActivity {

    private CircleImageView cv_img;
    private TextView tv_price,top_up_state,top_pay_type,top_pay_hao,tv_name,top_pay_time;
    private TextView tvTitle;
    private FrameLayout fl_img;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.account_details_activity);
        initView();
    }

    private void initView() {
        cv_img = findViewById(R.id.cv_img);
        tv_price = findViewById(R.id.tv_price);
        tv_name = findViewById(R.id.tv_name);
        top_up_state = findViewById(R.id.top_up_state);
        top_pay_type = findViewById(R.id.top_pay_type);
        top_pay_hao = findViewById(R.id.top_pay_hao);
        top_pay_time = findViewById(R.id.top_pay_time);
        tvTitle = findViewById(R.id.title_textview);
        fl_img = findViewById(R.id.fl_img);
        tvTitle.setText("帐单详情");
        fl_img.setOnClickListener(v -> finish());

        Map<String, Object> params = new HashMap<>();
        Map<String, String> params2 = new HashMap<>();
        params2.put("trade_id",getIntent().getStringExtra("trade_id"));
        params.put("req_bd",  params2);
        HttpClient.post(this, Constants.TRADEINFO, params, new CallBack<AccountBean.TradeListBean>() {
            @Override
            public void onSuccess(AccountBean.TradeListBean resultBean) {
                //支付状态
                tv_name.setText(resultBean.user_name);
                top_pay_time.setText(resultBean.getTrade_time().substring(0,resultBean.getTrade_time().length()-2));
                top_pay_type.setText(resultBean.getTrade_user_name());
                Glide.with(AccountDetailsActivity.this).load(resultBean.getTrade_user_logo()).into(cv_img);
                int trade_pay_type = resultBean.trade_pay_type;
                if (trade_pay_type == 1){
                    top_pay_type.setText("零钱");
                }if (trade_pay_type == 2){
                    top_pay_type.setText("微信");
                }
                if (resultBean.getTrade_type().equals("1")){
                    tv_price.setText("+" + UIUtils.getamount(resultBean.getTrade_amount()) + "元");
                }else if(resultBean.getTrade_type().equals("2")){
                    tv_price.setText("-" + UIUtils.getamount(resultBean.getTrade_amount()) + "元");
                }else if(resultBean.getTrade_type().equals("3")) {
                    tv_price.setText("+" + UIUtils.getamount(resultBean.getTrade_amount())+ "元");
                }else if(resultBean.getTrade_type().equals("4")) {
                    tv_price.setText("+" + UIUtils.getamount(resultBean.getTrade_amount())+ "元");
                }
                if (resultBean.trade_state == 1){
                    top_up_state.setText("成功");
                }else if(resultBean.trade_state == 2){
                    top_up_state.setText("失败");
                }else {
                    top_up_state.setText("待处理");
                }
                top_pay_hao.setText(resultBean.trade_desc);
            }
        });
    }
}
